 

/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  pool.bean;

import java.util.Hashtable;
import java.util.Vector;

import logger.PoolLogger;

import control.RequestParameter;

import dbmanager.DBManager;

import pool.tablename.Property_details;
import utility.ConvertToLower;

public class Property_details_Bean extends SubBean
{
	
	private Vector<Object> PropertyVector = new Vector<Object>();
	
	private Vector<Object> newPropertyVector = new Vector<Object>();
	private Vector<Object> oldPropertyVector = new Vector<Object>();	
	
	private String tableName = "property_details";
	
	private Hashtable<Object,Object> ViewHashtable = new Hashtable<Object, Object>();
	
	private String mid;
	private Property_details objProperty;

	
	public Property_details_Bean() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	public void clearPropertyVector()
	{
		this.PropertyVector.clear();
	}
	
	public void setId(String id)
	{
		//this.mid = id ;
		mid = gin.getId(id);
	}
	
	public void setMid(String mid)
	{
		//this.mid = mid ;
		this.mid = gin.getId(mid);
	}
	
	/**
	 * this function converts properties in vector in Property_details class format to insert
	 * @param vector containing properties
	 */
	@SuppressWarnings("unchecked")
	public void setPropertyVector(Vector<Object> vector)
	{
		for(Object object : vector)
		{			
			Hashtable<Object,Object> hashtable = (Hashtable<Object, Object>)object;
			
			hashtable = gin.ConvertPVtoVT(hashtable);
			hashtable = gin.convertMasterId(hashtable, tableName,process);
			
			
			PropertyVector.add(hashtable);		
		}
	}
	
	public void setPropertyHash(Hashtable<Object,Object> PropertyHash)
	{
		Vector<Object> vector = new Vector<Object>();
		Hashtable<Object,Object> propertyHash = new Hashtable<Object, Object>();
		
		propertyHash.putAll(PropertyHash);
		vector.add(propertyHash);
		//mid = propertyHash.get("mid").toString(); 
		setPropertyVector(vector);
	}
	/**
	 * insert() calls getInsert() of Property_details class to insert properties
	 * @return stringbuffer containing details of insertion
	 */
	@SuppressWarnings("unchecked")
	public StringBuffer insert()
	{
		 
		 StringBuffer sbrDTB = new StringBuffer();
		 
		 DBManager.setBeforeCommit();
		 objProperty = new Property_details();
		 //mid = gin.getId(mid);
		 objProperty.setId(mid);
		 objProperty.setRequestParameter(reqParam);
		 objProperty.setPropertyVector(PropertyVector);
		 sbrDTB.append( objProperty.getInsert());
		 
		 boolean flag = objProperty.getResult();
		 DBManager.setAfterCommit(flag);
		FLAG = flag;	
	
			return sbrDTB;
	}
	
	
	/**
	 * 
	 * @param oldPropertyHashis Hashtable of old property of property_details.  
	 */
	public void setOldPropertyHash(Hashtable<Object,Object> oldPropertyHash)
	{
		Hashtable<Object,Object> propertyHash = new Hashtable<Object, Object>();
					
		
		propertyHash.putAll(oldPropertyHash);
		propertyHash = gin.ConvertPVtoVT(propertyHash);
		propertyHash = gin.convertMasterId(propertyHash, tableName,process);
		
			
		mid = propertyHash.get("mid").toString(); 
			
		oldPropertyVector.add(propertyHash);
	}
	
	
	/**
	 * 
	 * @param newPropertyHash  Hashtable of new property of property_details to update  
	 */
	public void setNewPropertyHash(Hashtable<Object,Object> newPropertyHash)
	{
		Hashtable<Object,Object> propertyHash = new Hashtable<Object, Object>();
		propertyHash.putAll(newPropertyHash);
		propertyHash = gin.ConvertPVtoVT(propertyHash);
		propertyHash = gin.convertMasterId(propertyHash, tableName,process);
		propertyHash.put("mid", mid);
		
		
		newPropertyVector.add(propertyHash);
	}	
	
	
	/**
	 * this function converts properties of vector in Property_details class format to update
	 * @param vector containing old properties
	 */
	@SuppressWarnings("unchecked")
	public void setOldPropertyVector(Vector<Object> vector)
	{
		for(Object object : vector)
		{
			Hashtable<Object,Object> hasht = (Hashtable<Object, Object>)object;
			setOldPropertyHash(hasht);
		}
		
	}
	
	
	/**
	 * this function converts properties of vector in Property_details class format to update
	 * @param vector containing new properties
	 */
	@SuppressWarnings("unchecked")
	public void setNewPropertyVector(Vector<Object> vector)
	{
		for(Object object : vector)
		{
			Hashtable<Object,Object> hasht = (Hashtable<Object, Object>)object;
			setNewPropertyHash(hasht);
		}
		
	}
	
	
	/**
	 * update() calls directUpdate() of Property_details class to update any property
	 * @return stringbuffer containing details of updation
	 */
	public StringBuffer update()
	{
		StringBuffer sbrDTB = new StringBuffer();
		 
		DBManager.setBeforeCommit();
		 
		 objProperty = new Property_details();
		 
		 objProperty.setRequest(tableName);		 
		 objProperty.setRequestParameter(reqParam);
		 objProperty.setOldPropertyVector(oldPropertyVector);
		 objProperty.setNewPropertyVector(newPropertyVector);
		 objProperty.setId(mid);
		 sbrDTB.append( objProperty.getUpdate());
		 
		 boolean flag = objProperty.getResult();
		 DBManager.setAfterCommit(flag);
			
		 FLAG = flag;
		return sbrDTB;
	}
	
	
	/**
	 * this function converts hashtable to Property_details class format for view
	 * @param hashtable contains master object
	 */
	public void setViewHashtable(Hashtable<Object,Object> hashtable) 
	{

		Hashtable<Object,Object> PropertyHash = new Hashtable<Object, Object>();
		
		PropertyHash.putAll(hashtable);
		PropertyHash = gin.ConvertPVtoVT(PropertyHash);
		PropertyHash.putAll(gin.getHashMapOfValues(PropertyHash));
		PropertyHash.putAll(ConvertToLower.convertHashKey(PropertyHash));
		PropertyHash = gin.convertMasterId(PropertyHash, tableName,process);	
		PropertyHash.putAll(gin.getHashMapOfValues(PropertyHash));	
		
		ViewHashtable.putAll(PropertyHash);
	}
	
	
	/**
	 * view() calls getView() of Property_details class
	 * @return stringbuffer containing details of properties in message format
	 */	
	public StringBuffer view()
	{
	
		 StringBuffer sbrDTB = new StringBuffer();
		 
		 objProperty = new Property_details();
		 objProperty.setRequestParameter(reqParam);
		 objProperty.setViewHashtable(ViewHashtable);
		 objProperty.setPropertyVector(PropertyVector);
		 sbrDTB.append(objProperty.getView());
		 
	
		return sbrDTB;
	}
	
	
	@SuppressWarnings("unchecked")
	public StringBuffer delete()
	{
		 StringBuffer sbrDTB = new StringBuffer();
		 objProperty = new Property_details();
		 StringBuffer strbuf = new StringBuffer();
		 objProperty.setRequest(tableName);
		 objProperty.setProcess(process);
		 objProperty.setRequestParameter(reqParam);
		 objProperty.setId(mid);
		 objProperty.setPropertyVector(PropertyVector);
		 strbuf.append(objProperty.getDelete());
		return strbuf;
	
	}


	
		
	
	public static void main(String[] args) 
	{
		Property_details_Bean prop = new Property_details_Bean();
		prop.initPool();
		RequestParameter req = new RequestParameter();
		req.setUsername("+919922930640");
		req.setMessage("System Message");
		req.setPassword("123");
		req.setRequest("proerty_details");
		req.setProcess("del");
		prop.setReqParam(req);
		Vector<Object> property = new Vector<Object>();
		prop.setPropertyVector(property);
		prop.setMid("sendmail1");
		//prop.updateProperty();
		//prop.deleteProperty();
		prop.delete();
		
	}
}
